//
//  CCTabBar.m
//  BuDeJie
//
//  Created by demoncraz on 2017/2/9.
//  Copyright © 2017年 demoncraz. All rights reserved.
//

#import "CCTabBar.h"

@interface CCTabBar ()

@property (nonatomic, weak) UIButton *publishButton;

@end

@implementation CCTabBar

- (UIButton *)publishButton {
    if (_publishButton == nil) {
        UIButton *publishButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [publishButton setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_icon_38x38_"] forState:UIControlStateNormal];
        [publishButton setBackgroundImage:[UIImage imageNamed:@"tabBar_publish_click_icon_38x38_"] forState:UIControlStateHighlighted];
        [publishButton sizeToFit];
        
        [self addSubview:publishButton];
        _publishButton = publishButton;
    }
    return _publishButton;
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    NSInteger count = self.items.count + 1;
    CGFloat buttonW = self.frame.size.width / count;
    CGFloat buttonH = self.frame.size.height;
    NSInteger i = 0;
    //重新排列系统的tabBarItembutton （UITabBarButton）
    for (UIView *tabBarButton in self.subviews) {
        
        if ([tabBarButton isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            if (i == 2) {
                i += 1;
            }
            tabBarButton.frame = CGRectMake(buttonW * i, 0, buttonW, buttonH);
            i++;
        }
    }
    
    //添加publish按钮
    self.publishButton.center = CGPointMake(self.frame.size.width * 0.5, self.frame.size.height * 0.5);
    
    
    
}

@end
